<?php
/**
 * 用户控制器
 * @author maniac
 */
namespace app\manage\controller;

use app\common\logic\Users as UsersLogic;
use app\common\model\UserRoles;
use app\common\model\Columns AS ColumnsModel;

class Users extends Base
{
    /**
     * 列表页附加
     * @param  array $data 列表页数据
     */
    public function indexAttach($data)
    {
        $this->roles();
    }
    
    /**
     * 添加/编辑附件
     * @param array $info 要编辑的数据
     */
    public function addAttach($info)
    {
        $this->roles();
        $columns = ColumnsModel::field('id,parent_id,name,is_last')->order('id ASC')->select();
        $columns = $columns ? $columns->toArray() : [];
        $columns = recursion_one_array($columns);
        $this->assign('columns', $columns);
    }
    
    /**
     * where 查询条件
     * @return [type] [description]
     */
    public function where()
    {
        $role_id = input('get.role_id/d', 0);
        $where   = [
            ["type","eq",0]
        ];
        $where[]   = [
            ["id","neq",1]
        ];
        if ($role_id) {
            $where = [
                'role_id' => $role_id,
            ];
        }
        return $where;
    }
    
    /**
     * 获取所有会员角色
     */
    private function roles()
    {
        $roles = UserRoles::field('id,name')->order('id ASC')->select();
        $this->assign('roles', $roles);
    }

    /**
     * 修改后台密码
     */
    public function editPass(){
        $params=input("param.");

        $UsersLogic=new UsersLogic();
        $params['user_id']    = session('userid', '', session_prefix());

        $result=$UsersLogic->editpass($params);

        return $result;
    }
}
